package com.ruoyi.project.gxgw_modules.vipUsers.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.gxgw_modules.vipUsers.domain.VipRegist;
import com.ruoyi.project.gxgw_modules.vipUsers.domain.VipUsers;
import com.ruoyi.project.gxgw_modules.vipUsers.domain.VipUsersVO;
import com.ruoyi.project.gxgw_modules.vipUsers.service.IVipUsersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员用户 信息操作处理
 *
 * @author ruoyi
 * @date 2019-01-18
 */
@Controller
@RequestMapping("/gxgw_modules/vipUsers")
public class VipUsersController extends BaseController {
    private String prefix = "gxgw_modules/vipUsers";

    @Autowired
    private IVipUsersService vipUsersService;

    /*前端使用年份选择器，只传入年份*/
    @RequestMapping("/getChartByYear")
    @ResponseBody
    public List<VipRegist> getChartByYear(String year) {
        return vipUsersService.selectChartByYear(year);
    }

    @RequestMapping("/getChartBySeason")
    @ResponseBody
    public List<VipRegist> getChartBySeason(String year) {
        return vipUsersService.selectChartBySeason(year);
    }

    @RequestMapping("/getChartByMonth")
    @ResponseBody
    public List<VipRegist> getChartByMonth(String year,String month) {
        return vipUsersService.selectChartByMonth(year,month);
    }




    @RequiresPermissions("gxgw_modules:vipUsers:view")
    @GetMapping()
    public String vipUsers() {

        return prefix + "/vipUsers";
    }

    /**
     * 查询会员用户列表
     */
    @RequiresPermissions("gxgw_modules:vipUsers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VipUsersVO vipUsers) {
        startPage();
        List<VipUsersVO> list = vipUsersService.selectVipUsersList(vipUsers);
        return getDataTable(list);
    }

    /**
     * 导出会员用户列表
     */
    @RequiresPermissions("gxgw_modules:vipUsers:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VipUsersVO vipUsers) {
        List<VipUsersVO> list = vipUsersService.selectVipUsersList(vipUsers);
        ExcelUtil<VipUsersVO> util = new ExcelUtil<>(VipUsersVO.class);
        return util.exportExcel(list, "vipUsers");
    }

    /**
     * 删除会员用户
     */
    @RequiresPermissions("gxgw_modules:vipUsers:remove")
    @Log(title = "会员用户", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(vipUsersService.deleteVipUsersByIds(ids));
    }

    /**
     * 新增会员用户
     *//*
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	*/

    /**
     * 新增保存会员用户
     *//*
	@RequiresPermissions("gxgw_modules:vipUsers:add")
	@Log(title = "会员用户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(VipUsers vipUsers)
	{		
		return toAjax(vipUsersService.insertVipUsers(vipUsers));
	}

	/**
	 * 修改会员用户
	 */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Integer userId, ModelMap mmap) {
        VipUsers vipUsers = vipUsersService.selectVipUsersById(userId);
        mmap.put("vipUsers", vipUsers);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员用户
     */
    @RequiresPermissions("gxgw_modules:vipUsers:edit")
    @Log(title = "会员用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VipUsers vipUsers) {
        return toAjax(vipUsersService.updateVipUsers(vipUsers));
    }

}
